package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.ShopCommentRecordFight;
import com.addplus.townmall.server.api.model.town.expand.ShopCommentRecordExpand;
import com.addplus.townmall.server.api.model.town.expand.ShopCommentRecordFightExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 拼团商品会员评价详细表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-10-30
 */
public interface ShopCommentRecordFightMapper extends BaseAddMapper<ShopCommentRecordFight> {

    @Select("<script>" +
            "select\n" +
            "sr.*,\n" +
            "oi.shop_specification_sku_json as shop_specification_sku\n" +
            "from shop_comment_record_fight sr\n" +
            "left join order_items_fight as oi on sr.order_fight_id = oi.order_id and sr.shop_product_fight_id = oi.shop_product_id\n" +
            "<where>" +
            "sr.is_deleted = 0 and sr.shop_product_fight_id = #{params.shopProductId}" +
            "<if test=\"params.isImage != null\">" +
            " and sr.is_image = #{params.isImage}" +
            "</if>" +
            "<if test=\"params.commentType != null\">" +
            " and sr.comment_type = #{params.commentType}" +
            "</if>" +
            "</where>" +
            "order by sr.gmt_create desc" +
            "</script>"
    )
    List<ShopCommentRecordFightExpand> getShopCommentFightAllByShopType(Page page, @Param("params") Map<String, Object> parms);

    @Select("SELECT\n" +
            "\tscr.*,\n" +
            "\tsp.shop_name,\n" +
            "\tsp.shop_seal_img \n" +
            "FROM\n" +
            "\tshop_comment_record_fight scr\n" +
            "\tLEFT JOIN shop_product_fight sp ON sp.id = scr.shop_product_fight_id \n" +
            "WHERE\n" +
            "\tscr.member_id = #{memberId} \n" +
            "\tAND scr.order_fight_id = #{orderId} \n" +
            "\tAND scr.is_deleted = 0")
    List<ShopCommentRecordFightExpand> getCommentByOrderIdAndMemberId(@Param("memberId") Integer memberId, @Param("orderId") Integer orderId);
}
